package Classes.GameDatas// ActionScript file
{
	import Classes.Interfaces.I_Observer;

	/**
	 *游戏数据基类
	 * @author 葛增文
	 * 
	 */	
	public class GameData
	{
		private var _observers:Object;/*关注者存储器*/
		public function GameData():void
		{
			this.init();
		}
		
		private function init():void
		{
			this._observers=new Object;
		}
		
		/**
		 *添加关注者 
		 * @param observeType 关注类型
		 * @param observer 关注者
		 * 
		 */		
		public function addObserver(observeType:String,observer:I_Observer):void
		{
			for(var checkType:String in this.observers)
			{
				if(observeType==checkType)
				{
					(this.observers[checkType] as Array).push(observer);
					return;
				}
			}
			this.observers[observeType]=new Array;
			(this.observers[observeType] as Array).push(observer);
		}
		
		/**
		 *删除关注者 
		 * @param observeType 关注类型
		 * @param observer 关注者
		 * 
		 */		
		public function removeObserver(observeType:String,observer:I_Observer):void
		{
			for(var checkType:String in this.observers)
			{
				if(observeType==checkType)
				{
					for(var i:int=0;i<(this.observers[checkType] as Array).length;i++)
					{
						var checkObserver:I_Observer=(this.observers[checkType] as Array)[i];
						if(checkObserver==observer)
						{
							(this.observers[checkType] as Array).splice(i,1);
						}
					}
					return;
				}
			}
		}
		
		/**
		 *触发关注
		 * @param observeType 关注类型
		 * 
		 */		
		public function touchObserve(observeType:String):void
		{
			var observerAry:Array=this.observers[observeType];
			if(observerAry)
			{
				for each(var observer:I_Observer in observerAry)
				{
					observer.touchObserve(observeType);
				}
			}
		}
		
		
		public function release():void
		{
			this._observers=null;
		}	
		
		/*getter & setter*/
		public function get observers():Object
		{
			return _observers;
		}
	}
}